﻿namespace QLPhongKham.Report
{
    using DevExpress.XtraPrinting;
    using DevExpress.XtraPrinting.Preview;
    using DevExpress.XtraReports.Parameters;
    using DevExpress.XtraReports.UI;
    using QLPhongKham.Access;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.IO;
    using System.Windows.Forms;

    public class XtraReport1 : XtraReport
    {
        private string _filePath = "";
        private int _isolanin = 0;
        private General.DThongSo _tso = new General.DThongSo();
        private BottomMarginBand BottomMargin;
        public bool bPrinting = false;
        private IContainer components = null;
        private DetailBand Detail;
        public Parameter par_diachi = new Parameter();
        public Parameter par_dienthoai = new Parameter();
        public Parameter par_email = new Parameter();
        public Parameter par_tenbv = new Parameter();
        private TopMarginBand TopMargin;

        public XtraReport1()
        {
            this.InitializeComponent();
            string[] strArray = Directory.GetCurrentDirectory().Split(new char[] { '\\' });
            for (int i = 0; i < (strArray.Length - 1); i++)
            {
                this._filePath = this._filePath + strArray[i] + @"\";
            }
            this._filePath = this._filePath + "Report";
            if (!Directory.Exists(this._filePath))
            {
                Directory.CreateDirectory(this._filePath);
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public void f_load(DataSet data, string fileNameReport)
        {
            string fileName = this._filePath + @"\" + fileNameReport;
            try
            {
                base.LoadLayout(fileName);
                base.RequestParameters = false;
                base.Parameters.Clear();
                this.par_tenbv.Value = this._tso.pTenBV;
                this.par_diachi.Value = this._tso.pDiaChi;
                this.par_dienthoai.Value = this._tso.pDienThoai;
                this.par_email.Value = this._tso.pEmail;
                base.Parameters.Add(this.par_tenbv);
                base.Parameters.Add(this.par_diachi);
                base.Parameters.Add(this.par_dienthoai);
                base.Parameters.Add(this.par_email);
                base.SaveLayout(fileName);
                base.LoadLayout(fileName);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
            base.DataSource = data;
            if (this.bPrinting)
            {
                this.Print();
            }
            else
            {
                base.CreateDocument();
                new PrintPreviewFormEx { Text = fileNameReport, PrintingSystem = base.PrintingSystem }.ShowDialog();
            }
        }

        private void InitializeComponent()
        {
            this.Detail = new DetailBand();
            this.BottomMargin = new BottomMarginBand();
            this.TopMargin = new TopMarginBand();
            this.BeginInit();
            this.Detail.Name = "Detail";
            this.BottomMargin.Name = "BottomMargin";
            this.TopMargin.Name = "TopMargin";
            base.Bands.AddRange(new Band[] { this.TopMargin, this.Detail, this.BottomMargin });
            base.Version = "12.2";
            base.PrintProgress += new PrintProgressEventHandler(this.XtraReport1_PrintProgress);
            this.EndInit();
        }

        private void XtraReport1_PrintProgress(object sender, PrintProgressEventArgs e)
        {
            this._isolanin++;
        }

        public int pPrintingCount
        {
            get
            {
                return this._isolanin;
            }
        }
    }
}

